#!/bin/bash
echo "=======================Bulid stm32================="

echo "$1"
echo "$2"
echo "$3"

time=$(date "+%Y-%m-%d %H:%M:%S")
echo $time

project_path=$(cd `dirname $0`; pwd)
project_name="${project_path##*/}"

echo $project_path
echo $project_name

#stm32 build
cd $project_path
check_build_dir=`ls -l |grep "build"`
echo $check_build_dir
if [[ $check_build_dir =~ "build/" ]]
then
	echo "Has bulid Directroy!"
else
	echo "Create build Directory!"
	mkdir -p ./build
fi


cd $project_path/build/
cmake -D CMAKE_BUILD_TYPE=$2 ..

if [[ "$1" =~ "clean" ]]
then
	make clean-all-core
	rm -rf ./*
	echo "====================================....clean Success....========================================="
else
	echo "====================================....Build start....==============================================="
	make -j12
	echo "====================================....Build Success....========================================="
fi
